package com.intelligent.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.intelligent.pojo.PayableDetail;
import com.intelligent.service.PayableDetailService;
import com.intelligent.utils.Result;
import com.intelligent.vo.PayableDetailPageReq;
import com.intelligent.vo.PayableDetailResp;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/payable-detail")
public class PayableDetailController {

    @Resource
    private PayableDetailService payableDetailService;

    @PostMapping("/page")
    public Result<Page<PayableDetailResp>> page(@RequestBody PayableDetailPageReq req) {
        if (req.getPageNum() == null || req.getPageNum() < 1) req.setPageNum(1);
        if (req.getPageSize() == null || req.getPageSize() < 1) req.setPageSize(10);
        Page<PayableDetailResp> page = payableDetailService.page(req);
        return Result.success(page);
    }

    @GetMapping("/{id}")
    public Result<PayableDetailResp> detail(@PathVariable Long id) {
        PayableDetailResp resp = payableDetailService.detail(id);
        return resp == null ? Result.error("未找到明细") : Result.success(resp);
    }

    @PostMapping("/create")
    public Result<?> create(@RequestBody PayableDetail detail) {
        boolean ok = payableDetailService.create(detail);
        return ok ? Result.success(detail) : Result.error("保存失败");
    }
}



